﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Minio;
using Newtonsoft.Json;
using System.Net;
namespace MVC_System.Controllers
{
    public class UploadController1 : Controller
    {
        private readonly string _minioEndpoint;
        private readonly string _minioAccessKey;
        private readonly string _minioSecretKey;
        private readonly string _minioBucketName;

        public UploadController1(IOptions<MinioSettings> minioSettings)
        {
            _minioEndpoint = minioSettings.Value.Endpoint;
            _minioAccessKey = minioSettings.Value.AccessKey;
            _minioSecretKey = minioSettings.Value.SecretKey;
            _minioBucketName = minioSettings.Value.BucketName;
        }
        //[HttpPost]
        //public async Task<IActionResult> UploadImage(IFormFile imageFile)
        //{
        //    if (imageFile == null || imageFile.Length == 0)
        //    {
        //        return BadRequest("请选择要上传的图片");
        //    }
        //    try
        //    {
        //        var minioClient = new MinioClient();
        //        var exists = await minioClient.BucketExistsAsync(_minioBucketName);
        //        if (!exists)
        //        {
        //            await minioClient.MakeBucketAsync(_minioBucketName);
        //        }

        //        var objectName = Guid.NewGuid().ToString() + Path.GetExtension(imageFile.FileName);
        //        using (var stream = imageFile.OpenReadStream())
        //        {
        //            await minioClient.PutObjectAsync(_minioBucketName, objectName, stream, imageFile.Length);
        //        }

        //        return Ok("图片上传成功");
        //    }
        //    catch (Exception ex)
        //    {
        //        return StatusCode((int)HttpStatusCodes.Status500InternalServerError, "图片上传失败: " + ex.Message);
        //    }
        //}
    }
    public class MinioSettings
    {
        public string Endpoint { get; set; }
        public string AccessKey { get; set; }
        public string SecretKey { get; set; }
        public string BucketName { get; set; }
    }

}
